package com.define.ssh.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5 {

	/**
	 * 返回32位的md5密码
	 * 
	 * @param plainText
	 * @return
	 */
	public static String md5to32(String plainText) {
		try {
			final MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(plainText.getBytes());
			final byte b[] = md.digest();

			int i;

			final StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
			return buf.toString();
			// System.out.println("32位result: " + buf.toString());// 32位的加密
			// System.out.println("16位result: " + buf.toString().substring(8,
			// 24));// 16位的加密
		} catch (final NoSuchAlgorithmException e) {
			e.printStackTrace();
			return "";
		}
	}

	public static void main(String agrs[]) {
		final Md5 md51 = new Md5();
		System.out.println(Md5.md5to32("15018869351测试a235bc").toUpperCase());
	}

}
